from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-07 14:13:50.091927
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 07, Jul, 2022
Time: 14:13:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7131
Nobs: 710.000 HQIC: -50.0683
Log likelihood: 8876.58 FPE: 1.44060e-22
AIC: -50.2918 Det(Omega_mle): 1.27021e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298244 0.057461 5.190 0.000
L1.Burgenland 0.104455 0.037711 2.770 0.006
L1.Kärnten -0.109498 0.019994 -5.477 0.000
L1.Niederösterreich 0.211459 0.078856 2.682 0.007
L1.Oberösterreich 0.105824 0.077187 1.371 0.170
L1.Salzburg 0.257020 0.040367 6.367 0.000
L1.Steiermark 0.044202 0.052582 0.841 0.401
L1.Tirol 0.109745 0.042685 2.571 0.010
L1.Vorarlberg -0.061324 0.036934 -1.660 0.097
L1.Wien 0.045291 0.068215 0.664 0.507
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048423 0.120271 0.403 0.687
L1.Burgenland -0.034810 0.078931 -0.441 0.659
L1.Kärnten 0.041200 0.041848 0.985 0.325
L1.Niederösterreich -0.167842 0.165051 -1.017 0.309
L1.Oberösterreich 0.424020 0.161558 2.625 0.009
L1.Salzburg 0.288365 0.084490 3.413 0.001
L1.Steiermark 0.100816 0.110058 0.916 0.360
L1.Tirol 0.318719 0.089344 3.567 0.000
L1.Vorarlberg 0.028048 0.077305 0.363 0.717
L1.Wien -0.039521 0.142779 -0.277 0.782
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187445 0.029398 6.376 0.000
L1.Burgenland 0.089463 0.019293 4.637 0.000
L1.Kärnten -0.007927 0.010229 -0.775 0.438
L1.Niederösterreich 0.266141 0.040343 6.597 0.000
L1.Oberösterreich 0.137118 0.039490 3.472 0.001
L1.Salzburg 0.045863 0.020652 2.221 0.026
L1.Steiermark 0.019568 0.026902 0.727 0.467
L1.Tirol 0.091349 0.021838 4.183 0.000
L1.Vorarlberg 0.057063 0.018896 3.020 0.003
L1.Wien 0.115087 0.034899 3.298 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111677 0.029896 3.735 0.000
L1.Burgenland 0.045183 0.019620 2.303 0.021
L1.Kärnten -0.013764 0.010402 -1.323 0.186
L1.Niederösterreich 0.191601 0.041028 4.670 0.000
L1.Oberösterreich 0.303153 0.040159 7.549 0.000
L1.Salzburg 0.108315 0.021002 5.157 0.000
L1.Steiermark 0.104627 0.027358 3.824 0.000
L1.Tirol 0.104062 0.022209 4.686 0.000
L1.Vorarlberg 0.066472 0.019216 3.459 0.001
L1.Wien -0.021951 0.035491 -0.619 0.536
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134329 0.054528 2.463 0.014
L1.Burgenland -0.052669 0.035785 -1.472 0.141
L1.Kärnten -0.044334 0.018973 -2.337 0.019
L1.Niederösterreich 0.157315 0.074830 2.102 0.036
L1.Oberösterreich 0.139776 0.073247 1.908 0.056
L1.Salzburg 0.286777 0.038306 7.486 0.000
L1.Steiermark 0.047024 0.049898 0.942 0.346
L1.Tirol 0.167079 0.040506 4.125 0.000
L1.Vorarlberg 0.091867 0.035048 2.621 0.009
L1.Wien 0.075169 0.064732 1.161 0.246
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055276 0.043374 1.274 0.203
L1.Burgenland 0.037922 0.028465 1.332 0.183
L1.Kärnten 0.050964 0.015092 3.377 0.001
L1.Niederösterreich 0.217094 0.059523 3.647 0.000
L1.Oberösterreich 0.295328 0.058263 5.069 0.000
L1.Salzburg 0.048030 0.030470 1.576 0.115
L1.Steiermark 0.001600 0.039690 0.040 0.968
L1.Tirol 0.141277 0.032220 4.385 0.000
L1.Vorarlberg 0.072896 0.027879 2.615 0.009
L1.Wien 0.080531 0.051490 1.564 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175124 0.051873 3.376 0.001
L1.Burgenland -0.003523 0.034043 -0.103 0.918
L1.Kärnten -0.062957 0.018049 -3.488 0.000
L1.Niederösterreich -0.080688 0.071187 -1.133 0.257
L1.Oberösterreich 0.194652 0.069680 2.793 0.005
L1.Salzburg 0.056631 0.036441 1.554 0.120
L1.Steiermark 0.235650 0.047468 4.964 0.000
L1.Tirol 0.497529 0.038534 12.911 0.000
L1.Vorarlberg 0.043796 0.033342 1.314 0.189
L1.Wien -0.053659 0.061580 -0.871 0.384
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170690 0.059197 2.883 0.004
L1.Burgenland -0.010555 0.038850 -0.272 0.786
L1.Kärnten 0.063580 0.020598 3.087 0.002
L1.Niederösterreich 0.206751 0.081238 2.545 0.011
L1.Oberösterreich -0.074940 0.079519 -0.942 0.346
L1.Salzburg 0.213204 0.041586 5.127 0.000
L1.Steiermark 0.125417 0.054170 2.315 0.021
L1.Tirol 0.068776 0.043975 1.564 0.118
L1.Vorarlberg 0.118228 0.038049 3.107 0.002
L1.Wien 0.121316 0.070275 1.726 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362855 0.034269 10.588 0.000
L1.Burgenland 0.006041 0.022490 0.269 0.788
L1.Kärnten -0.023516 0.011924 -1.972 0.049
L1.Niederösterreich 0.217432 0.047028 4.623 0.000
L1.Oberösterreich 0.203429 0.046033 4.419 0.000
L1.Salzburg 0.043150 0.024074 1.792 0.073
L1.Steiermark -0.015033 0.031359 -0.479 0.632
L1.Tirol 0.105080 0.025457 4.128 0.000
L1.Vorarlberg 0.070269 0.022027 3.190 0.001
L1.Wien 0.032528 0.040682 0.800 0.424
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037566 0.138801 0.194801 0.156304 0.115274 0.103173 0.057475 0.217489
Kärnten 0.037566 1.000000 -0.015381 0.134196 0.056040 0.094930 0.435658 -0.053692 0.093575
Niederösterreich 0.138801 -0.015381 1.000000 0.334495 0.141543 0.293126 0.092720 0.175386 0.313587
Oberösterreich 0.194801 0.134196 0.334495 1.000000 0.227200 0.325050 0.176433 0.164340 0.262198
Salzburg 0.156304 0.056040 0.141543 0.227200 1.000000 0.137801 0.117071 0.137596 0.130168
Steiermark 0.115274 0.094930 0.293126 0.325050 0.137801 1.000000 0.144975 0.131540 0.070571
Tirol 0.103173 0.435658 0.092720 0.176433 0.117071 0.144975 1.000000 0.110313 0.142869
Vorarlberg 0.057475 -0.053692 0.175386 0.164340 0.137596 0.131540 0.110313 1.000000 -0.001496
Wien 0.217489 0.093575 0.313587 0.262198 0.130168 0.070571 0.142869 -0.001496 1.000000